define(function (require, exports, module) {
    var $ = require("jquery");
    require("pagination");
    var util = require("util");
    var ui = require("ui");
    var angular = require("angular");

    var ditchSourceBaseModule = angular.module('ditchSourceBaseModule', []);

    function baseDataService($http, $q, $location) {
        var service = {
            // 项目列表
            projectList: [],
            // 选择的项目 ID
            projectId: '',

            // 初始化查询表单数据
            initData: function () {
                var promises = [
                    // 项目列表
                    $http.get('/api/index.php?r=qmyx/customer-manage/get-project-list')
                ];

                return $q.all(promises).then(function (xhrs) {
                    var i = 0;
                    service.projectList = xhrs[i++].data.data;

                    service.projectId = service.projectList && service.projectList[0] && service.projectList[0].p_projectId
                    || service.projectId;
                    if (!service.projectId) {
                        return;
                    }
                    service.loaded = true;
                });
            }

        };

        return service;
    }

    ditchSourceBaseModule.factory('ditchSourceBaseSvr', ['$http', '$q', '$location', baseDataService]);


    module.exports = ditchSourceBaseModule;
})
